package easy

import "math"

func FindRestaurant(list1 []string, list2 []string) []string {
	map1 := make(map[string]int, len(list1))
	for i, s := range list1 {
		map1[s] = i
	}
	var ans []string
	indexSum := math.MaxInt32
	for i, s := range list2 {
		if j, ok := map1[s]; ok {
			if i+j < indexSum {
				indexSum = i + j
				ans = []string{s}
			} else if i+j == indexSum {
				ans = append(ans, s)
			}
		}
	}
	return ans
}
